package com.rui.study.algorithm.P_等差数列划分Ⅰ;

/**
 * @program: study
 * @description:
 * @author: Yaowr
 * @create: 2019-01-29 08:04
 **/
public class Solution2_无结果集 {
    public int numberOfArithmeticSlices(int[] A) {
        int n = A.length;
        if (n < 3) {
            return 0;
        }
        int count = 0, diff = A[1] - A[0], curCount = 0;
        for (int i = 2; i < n; i++) {
            int curDiff = A[i] - A[i-1];
            if (curDiff == diff) {
                count += ++curCount;
            } else {
                curCount = 0;
            }
            diff = curDiff;
        }
        return count;
    }



    public static void main(String[] args) {
        int[] a = {1,3,5,7,9};

        long start = System.currentTimeMillis();
        Solution2_无结果集 solution = new Solution2_无结果集();
        int result = solution.numberOfArithmeticSlices(a);
        long end = System.currentTimeMillis();
        System.out.println("等差数列划分：" + result + ", 耗时[" + (end - start) + "ms]");
    }
}
